package com.tenement.controller;

import com.tenement.common.Axios;
import com.tenement.entity.Resolution;
import com.tenement.enums.RespBusiness;
import com.tenement.service.ResolutionService;
import com.tenement.vo.QueryVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import java.util.List;


/**
 *  控制层。
 *
 * @author BertXie
 * @since 1.0.1
 */
@RestController
@RequestMapping("/resolution")
@RequiredArgsConstructor
@Api(tags = "决议管理接口")
public class ResolutionController {


    private final ResolutionService resolutionService;


    @ApiOperation(value = "操作决议数据")
    @PutMapping("operator")
    public Axios operator(@RequestBody Resolution resolution) {
        return resolutionService.getMapper().insertOrUpdateSelective(resolution) > 0 ? Axios.success(RespBusiness.SUCCESS) : Axios.error(RespBusiness.FAIL);
    }

    @ApiOperation(value = "决议数据列表")
    @PostMapping("list")
    @PreAuthorize("@exp.hasAuthority('tenement:resolution:list')")
    public Axios list(@RequestBody QueryVo queryVo) {
        return Axios.success(resolutionService.list(queryVo));
    }

    @ApiOperation(value = "删除决议数据")
    @DeleteMapping("remove")
    public Axios remove(@RequestBody List<Long> ids) {
        return resolutionService.remove(ids) > 0 ? Axios.success(RespBusiness.SUCCESS) : Axios.error(RespBusiness.FAIL);
    }

}
